import com.sun.org.apache.xerces.internal.impl.dtd.models.CMAny;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.layout.Pane;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class homework_13 extends Application {

    @Override
    public void start(Stage primaryStage) {
        Pane root = new Pane();
        root.setStyle("-fx-background-color: #87CEEB;");

        // 头部（主椭圆）
        Ellipse head = new Ellipse(400, 300, 180, 200);
        head.setFill(Color.PINK);
        head.setStroke(Color.DARKRED);
        head.setStrokeWidth(2);

        // 鼻子（椭圆组合）
        Group nose = createNose();

        // 眼睛（椭圆+圆形组合）
        Group eyes = createEyes();

        // 耳朵（贝塞尔曲线路径）
        Path leftEar = createEar(250, 150);
        Path rightEar = createEar(550, 150);

        // 嘴巴（二次曲线）
        QuadCurve mouth = new QuadCurve(300, 420, 400, 500, 500, 420);
        mouth.setFill(null);
        mouth.setStroke(Color.RED);
        mouth.setStrokeWidth(3);

        // 身体（路径组合）
        Path body = createBody();

        // 四肢
        Group legs = createLegs();

/*        // 尾巴（三次贝塞尔曲线）
        CubicCurve tail = new CubicCurve(650, 380, 720, 320, 750, 400, 680, 450);
        tail.setStroke(Color.PINK);
        tail.setStrokeWidth(15);
        tail.setFill(null);*/

        root.getChildren().addAll(body, head, leftEar, rightEar, nose, eyes, mouth, legs);

        Scene scene = new Scene(root, 800, 600);
        primaryStage.setTitle("JavaFX Peppa Pig");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    private Group createNose() {
        Ellipse noseBase = new Ellipse(400, 400, 40, 30);
        noseBase.setFill(Color.LIGHTPINK);

        Circle leftNostril = new Circle(380, 410, 8);
        Circle rightNostril = new Circle(420, 410, 8);

        return new Group(noseBase, leftNostril, rightNostril);
    }

    private Group createEyes() {
        Ellipse leftEye = new Ellipse(320, 250, 25, 35);
        Ellipse rightEye = new Ellipse(480, 250, 25, 35);
        leftEye.setFill(Color.WHITE);
        rightEye.setFill(Color.WHITE);

        Circle leftPupil = new Circle(320, 270, 12);
        Circle rightPupil = new Circle(480, 270, 12);

        return new Group(leftEye, rightEye, leftPupil, rightPupil);
    }

    private Path createEar(double x, double y) {
        Path ear = new Path(
                new MoveTo(x, y),
                new CubicCurveTo(x-50, y-80, x-80, y+50, x, y+100),
                new CubicCurveTo(x+30, y+80, x+20, y-30, x, y)
        );
        ear.setFill(Color.PINK);
        ear.setStroke(Color.DARKRED);
        ear.setStrokeWidth(2);
        return ear;
    }

    private Path createBody() {
        Path body = new Path();
        body.setFill(Color.RED);
        body.setStroke(Color.DARKRED);

        body.getElements().addAll(
                new MoveTo(300, 450),
                new CubicCurveTo(250, 500, 250, 600, 300, 650),
                new LineTo(500, 650),
                new CubicCurveTo(550, 600, 550, 500, 500, 450),
                new ClosePath()
        );
        return body;
    }

    private Group createLegs() {
        Path frontLeg = new Path(
                new MoveTo(350, 600),
                new CubicCurveTo(340, 680, 380, 680, 370, 600)
        );
        frontLeg.setStroke(Color.PINK);
        frontLeg.setStrokeWidth(25);

        Path backLeg = new Path(
                new MoveTo(450, 600),
                new CubicCurveTo(440, 680, 480, 680, 470, 600)
        );
        backLeg.setStroke(Color.PINK);
        backLeg.setStrokeWidth(25);

        return new Group(frontLeg, backLeg);
    }

    public static void main(String[] args) {
        launch(args);
    }
}